import { ref } from 'vue'
import { useAsyncAxios } from '@/utils/asyncFuncStore'
import { useCardStore } from '@/stores/cardStore'
import { useCurrActStroe } from '@/stores/currActStore'
import { useModalStore } from '@/stores/modalStore'
import ArtCommentSend from '@/components/index/artical/artCommentSend.vue'
import { storeToRefs } from 'pinia'
import { useRoute } from 'vue-router'
export default function () {
  const showSend = ref<number>()

  // 点赞
  async function addAcc(id: number, element: HTMLAnchorElement) {
    const { sendLike } = useAsyncAxios()
    const { thisArt } = storeToRefs(useCardStore())
    const { currUser } = storeToRefs(useCurrActStroe())
    const { changeData } = useModalStore()
    const formData = {
      articleId: thisArt.value.id,
      userId: currUser.value.id,
      commentId: id,
      isAcc: true
    }
    const { status, data } = await sendLike(formData)
    if (status === 200) {
      element.classList.add('isAcc')
    } else {
      changeData({ status, data })
    }
  }

  // 评论控制
  function addSendComment(id: number) {
    showSend.value = id
  }
  //   路径检查
  const route = useRoute()
  const path = route.path.substring(route.path.lastIndexOf('/') + 1)
  return {
    showSend,
    addAcc,
    addSendComment,
    ArtCommentSend
  }
}
